//
//  LGSchedulHomeTimeCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/28.
//

#import "LGSchedulHomeTimeCell.h"

@interface LGSchedulHomeTimeCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *countLabel;
/**   */
@property (nonatomic , strong)UILabel *adressLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)NSDictionary *weekDic;
@end

@implementation LGSchedulHomeTimeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.weekDic = @{@"0":@"周日",@"1":@"周一",@"2":@"周二",@"3":@"周三",@"4":@"周四",@"5":@"周五",@"6":@"周六"};
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSArray *weekArray = dataDic[@"week_days"];
    NSString *weekDay = @"";
    if(weekArray.count == 7){
        weekDay = [NSString stringWithFormat:@"每日 %@",dataDic[@"time"]];
    }else{
        for (NSInteger i=0; i<weekArray.count; i++) {
            NSString *key = LGNSString(weekArray[i]);
            weekDay = (weekDay.length>0)?[NSString stringWithFormat:@"%@ %@",weekDay,self.weekDic[key]]:self.weekDic[key];
        }
        weekDay = [NSString stringWithFormat:@"%@  %@",weekDay,dataDic[@"time"]];
    }
    self.timeLabel.text = weekDay;
    self.countLabel.text = [NSString stringWithFormat:@"%ld分钟，%@人",[dataDic[@"duration"] integerValue]/60,dataDic[@"total"]];
    NSString *adress = @"";
    if (![LGNSString(dataDic[@"compound"]) isEmptyString]) {
        adress = LGNSString(dataDic[@"compound"]);
    }
    if (![LGNSString(dataDic[@"visit_address"]) isEmptyString]) {
        adress = adress.length>0?[NSString stringWithFormat:@"%@  %@",adress,dataDic[@"visit_address"]]:LGNSString(dataDic[@"visit_address"]);
    }
    self.adressLabel.text = adress;
    CGFloat adressTop = (adress.length>0)?viewPix(5):0;
    [self.adressLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.countLabel.mas_bottom).offset(adressTop);
    }];
}

-(void)setShowTitle:(BOOL)showTitle{
    _showTitle = showTitle;
    self.titleLabel.hidden = !showTitle;
    CGFloat topMargin = (showTitle == YES)?viewPix(35):viewPix(5);
    [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(topMargin);
    }];
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.countLabel];
    [self.contentView addSubview:self.adressLabel];
    [self.contentView addSubview:self.tipView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(10));
        make.left.equalTo(self.contentView).offset(viewPix(28));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
    }];
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(viewPix(5));
        make.left.right.equalTo(self.timeLabel);
//        make.bottom.equalTo(self.contentView).offset(-viewPix(5));
    }];
    
    [self.adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.countLabel.mas_bottom).offset(viewPix(5));
        make.left.right.equalTo(self.timeLabel);
        make.bottom.equalTo(self.contentView).offset(-viewPix(5));
    }];
    
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.centerY.equalTo(self.timeLabel.mas_bottom);
        make.width.height.equalTo(@(viewPix(12)));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"排班" colorString:@"#3291FF" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)countLabel{
    if(!_countLabel){
        _countLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _countLabel;
}

-(UILabel *)adressLabel{
    if(!_adressLabel){
        _adressLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _adressLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
